﻿using System;
using System.IO;
using MSWord = Microsoft.Office.Interop.Word;

namespace OfficeToPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var fileInfo = new FileInfo("Temp/采购入库扫描项目目标及实现方式.docx");
            Console.WriteLine(fileInfo.FullName);


            object filePathObject = fileInfo.FullName;
            var application = new MSWord.ApplicationClass();
            MSWord.Document document = application.Documents.Open(ref filePathObject);

            fileInfo = new FileInfo($"Temp/{Path.GetFileNameWithoutExtension(filePathObject.ToString())}.pdf");
            document.ExportAsFixedFormat(fileInfo.FullName, MSWord.WdExportFormat.wdExportFormatPDF);
            Console.WriteLine(document.Saved);
            document.Close();
           

            //WordToPDF(fileInfo.FullName);
        }

        //static void WordToPDF(string filePath)
        //{
        //    object filePathObject = filePath;
        //    var application = new MSWord.ApplicationClass();
        //    MSWord.Document document = application.Documents.Open(ref filePathObject);

        //    object newFileName = $"{Path.GetFileNameWithoutExtension(filePath)}.pdf";
        //    document.SaveAs2(ref newFileName);
        //}
    }
}
